package com.barnabot.bigo.util;

import org.hibernate.Session;  
import org.hibernate.SessionFactory;  
import org.hibernate.cfg.Configuration;  
import org.hibernate.service.ServiceRegistry;  
import org.hibernate.service.ServiceRegistryBuilder;  

import com.barnabot.bigo.cliente.Cliente;


//import com.sun.tools.ws.wsdl.document.jaxws.Exception;
//step 1
public class HibernateUtil {
	private static SessionFactory factory;  
    
    static {  
        Configuration cfg = new Configuration(); // Nao preciso chamar .configure(), porque nao uso hibernate.cfg.xml, uso hibernate.properties
        cfg.addAnnotatedClass(Cliente.class); // Aqui coloco as classes que tem as anotacoes  
        ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();  
        factory = cfg.buildSessionFactory(serviceRegistry);  
        /*
    	// barnhen begin
		try {
			Configuration cfg = new Configuration();
			cfg.configure("hibernate.cfg.xml");
			return cfg.buildSessionFactory();
			
		} catch (Throwable e) {
			// TODO: handle exception
			System.out.println("database connection not working\n " + e);
			throw new ExceptionInInitializerError();
		}
		// barnhen end
		*/
    }
        

    public static Session getSession() {  
        return factory.openSession();  
    }  
      
}  